package com.deng.maintenance.vote.view
{
	import com.deng.maintenance.vote.vo.VoteValueVo;
	
	import flash.events.FocusEvent;
	
	import mx.controls.Alert;
	import mx.controls.TextInput;
	import mx.events.FlexEvent;
	import mx.resources.ResourceManager;
	import mx.utils.StringUtil;

	public class VoteValueXishuIT extends TextInput
	{
		private var pvo:VoteValueVo;
		public function VoteValueXishuIT()
		{	
			this.restrict = "-0-9\.";
			this.width = 40;
			this.addEventListener(FocusEvent.FOCUS_OUT,updateData);
			this.addEventListener(FlexEvent.CREATION_COMPLETE,showHandler);
			this.addEventListener(FlexEvent.SHOW,showHandler);
			this.addEventListener(FlexEvent.DATA_CHANGE,showHandler);
			super();
		}
		
		private function updateData(event:FocusEvent):void{
			if(isNaN(Number(this.text))){
				Alert.show(ResourceManager.getInstance().getString("lang", "input_item_error"));
				return;
			}
			pvo.xishu = StringUtil.trim(this.text);	
			
			this.data = pvo;	
		}
		private function showHandler(event:FlexEvent):void{
			pvo = this.data as VoteValueVo;
			if(pvo.valid == 1){
				this.enabled = false;
			}else{
				this.enabled = true;
			}
			if(pvo.xishu == null){
				this.text = "1";
			}else{
				this.text = pvo.xishu;
			}
		}
	}
}